package org.framework.lazy.cloud.network.heartbeat.server.standalone.application.impl;

import jakarta.annotation.Resource;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.LazyNettyClientRouteApplication;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.assembler.LazyNettyClientRouteDTOAssembler;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.command.lazy.netty.client.route.*;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.application.dto.LazyNettyClientRouteDTO;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.route.LazyNettyClientRoute;
import org.framework.lazy.cloud.network.heartbeat.server.standalone.domain.model.lazy.netty.client.route.LazyNettyClientRouteRepository;
import org.wu.framework.lazy.orm.database.lambda.domain.LazyPage;
import org.wu.framework.lazy.orm.web.plus.stereotype.LazyApplication;
import org.wu.framework.web.response.Result;

import java.util.List;
import java.util.stream.Collectors;

/**
 * describe 客户端代理路由规则
 *
 * @author Jia wei Wu
 * @date 2025/04/05 09:00 晚上
 * @see org.wu.framework.lazy.orm.core.persistence.reverse.lazy.ddd.DefaultDDDLazyApplicationImpl
 **/
@LazyApplication
public class LazyNettyClientRouteApplicationImpl implements LazyNettyClientRouteApplication {

    @Resource
    LazyNettyClientRouteRepository lazyNettyClientRouteRepository;

    /**
     * describe 新增客户端代理路由规则
     *
     * @param lazyNettyClientRouteStoryCommand 新增客户端代理路由规则
     * @return {@link Result<LazyNettyClientRoute>} 客户端代理路由规则新增后领域对象
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<LazyNettyClientRoute> story(LazyNettyClientRouteStoryCommand lazyNettyClientRouteStoryCommand) {
        LazyNettyClientRoute lazyNettyClientRoute = LazyNettyClientRouteDTOAssembler.INSTANCE.toLazyNettyClientRoute(lazyNettyClientRouteStoryCommand);
        return lazyNettyClientRouteRepository.story(lazyNettyClientRoute);
    }

    /**
     * describe 批量新增客户端代理路由规则
     *
     * @param lazyNettyClientRouteStoryCommandList 批量新增客户端代理路由规则
     * @return {@link Result<List<LazyNettyClientRoute>>} 客户端代理路由规则新增后领域对象集合
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<List<LazyNettyClientRoute>> batchStory(List<LazyNettyClientRouteStoryCommand> lazyNettyClientRouteStoryCommandList) {
        List<LazyNettyClientRoute> lazyNettyClientRouteList = lazyNettyClientRouteStoryCommandList.stream().map(LazyNettyClientRouteDTOAssembler.INSTANCE::toLazyNettyClientRoute).collect(Collectors.toList());
        return lazyNettyClientRouteRepository.batchStory(lazyNettyClientRouteList);
    }

    /**
     * describe 更新客户端代理路由规则
     *
     * @param lazyNettyClientRouteUpdateCommand 更新客户端代理路由规则
     * @return {@link Result<LazyNettyClientRoute>} 客户端代理路由规则领域对象
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<LazyNettyClientRoute> updateOne(LazyNettyClientRouteUpdateCommand lazyNettyClientRouteUpdateCommand) {
        LazyNettyClientRoute lazyNettyClientRoute = LazyNettyClientRouteDTOAssembler.INSTANCE.toLazyNettyClientRoute(lazyNettyClientRouteUpdateCommand);
        return lazyNettyClientRouteRepository.story(lazyNettyClientRoute);
    }

    /**
     * describe 查询单个客户端代理路由规则
     *
     * @param lazyNettyClientRouteQueryOneCommand 查询单个客户端代理路由规则
     * @return {@link Result<LazyNettyClientRouteDTO>} 客户端代理路由规则DTO对象
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<LazyNettyClientRouteDTO> findOne(LazyNettyClientRouteQueryOneCommand lazyNettyClientRouteQueryOneCommand) {
        LazyNettyClientRoute lazyNettyClientRoute = LazyNettyClientRouteDTOAssembler.INSTANCE.toLazyNettyClientRoute(lazyNettyClientRouteQueryOneCommand);
        return lazyNettyClientRouteRepository.findOne(lazyNettyClientRoute).convert(LazyNettyClientRouteDTOAssembler.INSTANCE::fromLazyNettyClientRoute);
    }

    /**
     * describe 查询多个客户端代理路由规则
     *
     * @param lazyNettyClientRouteQueryListCommand 查询多个客户端代理路由规则
     * @return {@link Result<List<LazyNettyClientRouteDTO>>} 客户端代理路由规则DTO对象
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<List<LazyNettyClientRouteDTO>> findList(LazyNettyClientRouteQueryListCommand lazyNettyClientRouteQueryListCommand) {
        LazyNettyClientRoute lazyNettyClientRoute = LazyNettyClientRouteDTOAssembler.INSTANCE.toLazyNettyClientRoute(lazyNettyClientRouteQueryListCommand);
        return lazyNettyClientRouteRepository.findList(lazyNettyClientRoute).convert(lazyNettyClientRoutes -> lazyNettyClientRoutes.stream().map(LazyNettyClientRouteDTOAssembler.INSTANCE::fromLazyNettyClientRoute).collect(Collectors.toList()));
    }

    /**
     * describe 分页查询多个客户端代理路由规则
     *
     * @param lazyNettyClientRouteQueryListCommand 分页查询多个客户端代理路由规则
     * @return {@link Result<LazyPage<LazyNettyClientRouteDTO>>} 分页客户端代理路由规则DTO对象
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<LazyPage<LazyNettyClientRouteDTO>> findPage(int size, int current, LazyNettyClientRouteQueryListCommand lazyNettyClientRouteQueryListCommand) {
        LazyNettyClientRoute lazyNettyClientRoute = LazyNettyClientRouteDTOAssembler.INSTANCE.toLazyNettyClientRoute(lazyNettyClientRouteQueryListCommand);
        return lazyNettyClientRouteRepository.findPage(size, current, lazyNettyClientRoute).convert(page -> page.convert(LazyNettyClientRouteDTOAssembler.INSTANCE::fromLazyNettyClientRoute));
    }

    /**
     * describe 删除客户端代理路由规则
     *
     * @param lazyNettyClientRouteRemoveCommand 删除客户端代理路由规则
     * @return {@link Result<LazyNettyClientRoute>} 客户端代理路由规则
     * @author Jia wei Wu
     * @date 2025/04/05 09:00 晚上
     **/

    @Override
    public Result<LazyNettyClientRoute> remove(LazyNettyClientRouteRemoveCommand lazyNettyClientRouteRemoveCommand) {
        LazyNettyClientRoute lazyNettyClientRoute = LazyNettyClientRouteDTOAssembler.INSTANCE.toLazyNettyClientRoute(lazyNettyClientRouteRemoveCommand);
        return lazyNettyClientRouteRepository.remove(lazyNettyClientRoute);
    }

}